package com.gel.aiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
/*转换为向量并存储*/
@Configuration
public class LoveAppVectorStoreConfig {
    @Resource
    private LoveAppDocumentLoader loveAppDocumentLoader;
    @Resource
    private MyTokenTextSplitter myTokenTextSplitter;
    @Resource
    private MyKeywordEnricher myKeywordEnricher;
    @Bean
    public VectorStore loveAppVectorStore(EmbeddingModel embeddingModel) {
        SimpleVectorStore vectorStore = SimpleVectorStore.builder(embeddingModel)
                .build();
        /*加载文件*/
        List<Document> documents = loveAppDocumentLoader.laodMarkdowns();
        //自定义切割器
//        List<Document> documents1 = myTokenTextSplitter.splitCustomized(documents);
        //关键字增强器（自动补充关键词元信息）
        List<Document> documents1 = myKeywordEnricher.enrichDocuments(documents);
        vectorStore.doAdd( documents1);
        return vectorStore;
    }
}
